﻿DROP TRIGGER IF EXISTS  `pk_goods_log`;
CREATE  TRIGGER `pk_goods_log` AFTER INSERT ON `open_goods`
  FOR EACH ROW BEGIN
DECLARE pkf varchar(50) DEFAULT "";
SELECT pk_from INTO pkf FROM open_pk_log WHERE pk_from="goods";
if pkf <> "goods" then
   INSERT INTO open_pk_log SET pk_from = 'goods', pk_id = NEW.goods_id;
ELSE
    update open_pk_log SET pk_id = NEW.goods_id WHERE pk_from = 'goods';
end if;
END;